Skip to content

feat: implement core/embed block for youtube videos#377

Merged
moonmeister merged 1 commit into
mainfrom
feat-core/embed
Jun 16, 2026
Merged

feat: implement core/embed block for youtube videos#377
moonmeister merged 1 commit into
mainfrom
feat-core/embed

Conversation

@moonmeister

@moonmeister moonmeister commented Jun 16, 2026

Copy link
Copy Markdown
Member

also adds html fallback for unknown blocks

@headless-platform-by-wp-engine

Copy link
Copy Markdown

Check out the recent updates to your Headless Platform preview environment:

App Environment URL Build
faustjs.org preview-env-feat-core/embed https://hx…wered.com ✅ (logs)

Learn more about preview environments in our documentation.

@Fran-A-Dev Fran-A-Dev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@moonmeister moonmeister merged commit 973d437 into main Jun 16, 2026
5 checks passed
@moonmeister moonmeister deleted the feat-core/embed branch June 16, 2026 19:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a custom core/embed block renderer to support YouTube embeds with a privacy-friendly youtube-nocookie.com iframe, and ensures HTML is available for fallback rendering (e.g., for blocks/providers the app doesn’t explicitly handle).

Changes:

  • Register a new CoreEmbed block component in the WordPress blocks registry.
  • Implement YouTube-specific embed rendering (iframe) with a fallback to renderedHtml.
  • Extend the single blog post GraphQL query to fetch renderedHtml and include the CoreEmbed fragment.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/wp-blocks/index.js Registers the new CoreEmbed block in the blocks map used by the provider.
src/wp-blocks/core-embed.jsx Adds the CoreEmbed renderer with YouTube URL parsing + HTML fallback + GraphQL fragment.
src/pages/blog/[slug].jsx Updates the post query to fetch renderedHtml and include the CoreEmbed fragment.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +10 to +38
function getYouTubeId(url) {
if (!url) return;
try {
// eslint-disable-next-line n/prefer-global/url
const parsed = new URL(url);
const host = parsed.hostname.replace(/^www\./, "");
if (host === "youtu.be") {
return parsed.pathname.slice(1).split("/")[0] || undefined;
}

if (host.endsWith("youtube.com") || host.endsWith("youtube-nocookie.com")) {
if (parsed.pathname === "/watch") {
return parsed.searchParams.get("v");
}

const match = parsed.pathname.match(
/^\/(?:embed|shorts|v)\/(?<id>[^/?#]+)/,
);
if (match) return match.groups?.id;
}
} catch {
// Fall through to regex below
}

const fallback = url.match(
/(?:youtube\.com\/(?:watch\?v=|embed\/|shorts\/|v\/)|youtu\.be\/)(?<id>[\w-]{11})/,
);
return fallback ? fallback.groups?.id : undefined;
}
Comment on lines +44 to +46
if (providerNameSlug === "youtube" || /youtu\.?be/i.test(url ?? "")) {
const videoId = getYouTubeId(url);
if (videoId) {
Comment on lines +50 to +59
{/* eslint-disable-next-line react/iframe-missing-sandbox */}
<iframe
className="absolute inset-0 h-full w-full border-0"
src={`https://www.youtube-nocookie.com/embed/${videoId}`}
title={caption || "YouTube video"}
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
referrerPolicy="strict-origin-when-cross-origin"
allowFullScreen
/>
Comment thread src/pages/blog/[slug].jsx
name
id: clientId
parentId: parentClientId
renderedHtml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants